package com.yirui.serialcomm.core.protocol;

/**
 * @author Dujie
 * @create 2025/8/13
 * @since 1.0.0
 */
public class SimplePortAllocator implements PortAllocator{
    private Context context;
    private int tcp;
    private int udp;
    private int step = 1;
    private static final int MAX = 65535;
    public SimplePortAllocator(Context context, int step) {
       this.context = context;
       this.tcp = context.getTcpPort();
       this.udp = context.getUdpPort();
       this.step = step;
    }
    public int getTcp(){
        this.tcp = tcp+step;
        if(this.tcp>MAX){
            this.tcp = context.getTcpPort();
        }
        return this.tcp;
    }
    public int getUdp(){
        this.udp = udp+step;
        if(this.udp>MAX){
            this.udp = context.getUdpPort();
        }
        return this.udp;
    }

}
